package com.getpebble.android.framework.protocol.outbound;

import android.graphics.Bitmap;
import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.util.ByteUtils;
import com.getpebble.android.framework.util.PblBitmap;
import com.sun.mail.smtp.SMTPMessage;

public class PblOutboundAppCustomizeMessage extends PblOutboundMessage {
    private final AppType mAppType;
    private final Field mField;
    private Bitmap mIcon;
    private String mTitle;

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppCustomizeMessage$Field = new int[Field.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppCustomizeMessage$Field[Field.NAME.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppCustomizeMessage$Field[Field.ICON.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
        }
    }

    public enum AppType {
        SPORTS((byte) 0),
        GOLF((byte) 1),
        UNKNOWN((byte) -1);
        
        private byte mType;

        private AppType(byte type) {
            this.mType = type;
        }

        public byte getValue() {
            return this.mType;
        }

        public static AppType fromByte(byte b) {
            for (AppType r : values()) {
                if (r.mType == b) {
                    return r;
                }
            }
            return UNKNOWN;
        }
    }

    public enum Field {
        NAME((byte) 0),
        ICON(Byte.MIN_VALUE);
        
        private byte mField;

        private Field(byte field) {
            this.mField = field;
        }

        public byte getValue() {
            return this.mField;
        }
    }

    private PblOutboundAppCustomizeMessage(Field field, AppType appType) {
        super(EndpointId.APP_CUSTOMIZE);
        if (field == null) {
            throw new IllegalArgumentException("field cannot be null");
        } else if (appType == null) {
            throw new IllegalArgumentException("appType cannot be null");
        } else if (AppType.UNKNOWN.equals(appType)) {
            throw new IllegalArgumentException("appType cannot be UNKNOWN");
        } else {
            this.mField = field;
            this.mAppType = appType;
        }
    }

    public static PblOutboundAppCustomizeMessage createCustomizeTitleMessage(AppType appType, String title) {
        if (title == null) {
            throw new IllegalArgumentException("title cannot be null");
        }
        PblOutboundAppCustomizeMessage message = new PblOutboundAppCustomizeMessage(Field.NAME, appType);
        message.mTitle = title;
        return message;
    }

    public static PblOutboundAppCustomizeMessage createCustomizeIconMessage(AppType appType, Bitmap icon) {
        if (icon == null) {
            throw new IllegalArgumentException("icon cannot be null");
        }
        PblOutboundAppCustomizeMessage message = new PblOutboundAppCustomizeMessage(Field.ICON, appType);
        message.mIcon = icon;
        return message;
    }

    public synchronized byte[] getBytes() {
        if (!areBytesCached()) {
            addBytes(Byte.valueOf((byte) (this.mField.getValue() | this.mAppType.getValue())));
            switch (AnonymousClass1.$SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppCustomizeMessage$Field[this.mField.ordinal()]) {
                case SMTPMessage.RETURN_FULL /*1*/:
                    ByteUtils.writeNullTerminatedString(this, this.mTitle);
                    break;
                case SMTPMessage.RETURN_HDRS /*2*/:
                    addBytes(PblBitmap.fromAndroidBitmap(this.mIcon).toByteBuffer());
                    break;
            }
        }
        return super.getBytes();
    }
}
